<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>23-校验交互队列比延时队列优先级高</title>
  </head>
  <body>
    <button id="count">计时</button>
    <button id="active">交互</button>
    <p id="text">我是文本</p>

    <script>
      // 延时函数
      function delay(duration) {
        var start = Date.now();
        while (Date.now() - start < duration) {}
      }
      var textDom = document.getElementById("text");

      document.getElementById("count").addEventListener("click", function () {
        console.log("点击了计时按钮");
        setTimeout(() => {
          console.log("执行了延时队列");
          // delay(3000);
        }, 100);

        delay(3000);
        textDom.textContent = "Hello World";
        console.log("============");
      });
      document.getElementById("active").addEventListener("click", function () {
        console.log("执行了交互队列");
        delay(3000);
      });
    </script>
  </body>
</html>
